<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
 
class wap_ctl_passport extends wap_controller{

    public function __construct($app)
    {
        parent::__construct($app);
        header("cache-control: no-store, no-cache, must-revalidate");
    }
    
    function index(){
        $auth = pam_auth::instance(pam_account::get_account_type('desktop'));
        $auth->set_appid($this->app->app_id);
        $redirect_url = app::get('wap')->router()->gen_url(array('ctl'=>'delivery','act'=>'index'), true);
        $redirect_url = base64_encode($redirect_url);
        $auth->set_redirect_url($redirect_url);
        $this->pagedata['desktop_url'] = kernel::router()->app->base_url(1);

		$conf = base_setup_config::deploy_info();
        $passport = kernel::single('pam_passport_wap');
        if($auth->is_module_valid('pam_passport_wap','desktop')){
            $this->pagedata['passports'][] = array(
                    'html'=>$passport->get_login_form($auth,'wap','basic-login.html',$pagedata),     
                );
        }

        $this->display('login.html');
    }
    
    function gen_vcode(){
        $vcode = kernel::single('base_vcode');
        $vcode->length(4);
        $vcode->verify_key($this->app->app_id);
        $vcode->display();
    }

    function logout($backurl='index.php'){
        $url = app::get('wap')->router()->gen_url(array('ctl'=>'passport','act'=>'index'), true);
        $this->begin($url);

        $this->user->login();
        $this->user->logout();
        $auth = pam_auth::instance(pam_account::get_account_type('desktop'));
        $passport = kernel::single('pam_passport_wap');
        if($auth->is_module_valid('pam_passport_wap','desktop')){
            $passport->loginout($auth,$backurl);
        }

        kernel::single('base_session')->destory();
		$this->end(true,'已成功退出系统,正在转向...');
    }
     

}
